package net.wanho.controller;

import cn.hutool.json.JSONUtil;
import net.wanho.vo.AjaxResult;
import net.wanho.websocket.WebSocketServer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Author：汤小洋
 * Date：2023-10-20 10:48
 * Description：<描述>
 */
@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrderController {

    @Resource
    private WebSocketServer webSocketServer;

    @GetMapping("/reminder")
    public AjaxResult reminder(int orderId){
        // 基于WebSocket发送消息，实现催单
        Map<String,Object> map = new HashMap<>();
        map.put("type", 1); // 消息类型，1表示催单 2表示新订单 3表示退单
        map.put("orderId", orderId);
        map.put("orderNumber", "20231020012536456123869");
        webSocketServer.sendToAllClient(JSONUtil.toJsonStr(map));

        return AjaxResult.success();
    }

}
